﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ChangeFileStamps
{
    class Program
    {
        static void Main(string[] args)
        {
            string dir;

            if (args.Length == 0)
            {
                Console.WriteLine("Please enter the directory you wish to change?");
                dir = Console.ReadLine();
            }
            else
            {
                dir = args[0];
            }

            WalkDirectoryTree(new System.IO.DirectoryInfo(dir));
            // Keep the console window open in debug mode.
            Console.WriteLine("Press any key");
            Console.ReadKey();
        }

        static void WalkDirectoryTree(System.IO.DirectoryInfo root)
        {
            System.IO.FileInfo[] files = null;
            System.IO.DirectoryInfo[] subDirs = null;

            // First, process all the files directly under this folder
            try
            {
                files = root.GetFiles("*.*");
            }
            // This is thrown if even one of the files requires permissions greater
            // than the application provides.
            catch (UnauthorizedAccessException e)
            {
                Console.WriteLine(e.Message);
            }

            catch (System.IO.DirectoryNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }

            if (files != null)
            {
                foreach (System.IO.FileInfo fi in files)
                {
                    // In this example, we only access the existing FileInfo object. If we
                    // want to open, delete or modify the file, then
                    // a try-catch block is required here to handle the case
                    // where the file has been deleted since the call to TraverseTree().

                    System.IO.File.SetCreationTime(fi.FullName, DateTime.Now);
                    System.IO.File.SetLastWriteTime(fi.FullName, DateTime.Now);

                    

                    Console.WriteLine(fi.FullName);
                }

                // Now find all the subdirectories under this directory.
                subDirs = root.GetDirectories();

                foreach (System.IO.DirectoryInfo dirInfo in subDirs)
                {
                    // Resursive call for each subdirectory.
                    WalkDirectoryTree(dirInfo);
                }
            }


        }
    }
}
